package com.atguigu.test2;

import java.util.Arrays;

/**
 * @author 路飞
 * @date 2024/3/28 10:30
 * @description 2、请写一个冒泡排序，实现{5,7,3,9,2}从小到大排序
 */
public class Exer2 {
    public static void main(String[] args) {
        int[] arr = {5,7,3,9,2};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j + 1] < arr[j]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
